

 *********************************** 
 * Program for bootstrapping *
 ***********************************
 
program define debt_boot_3, rclass
 
	use "File 1 for Bootstrap.dta", clear
	
	bsample, cluster(id)

sort bucket
by bucket: egen count = count(bucket) 

count if ltd_iss_all_other >= 0 
scalar totalcount = r(N)
drop if ltd_iss_all_other > 60000 | ltd_iss_all_other < 1000

collapse (mean) count bucket1-bucket16 bucket_2-bucket_14 Qdummy bucket_Q bucket2_Q bucket3_Q bucket4_Q bucket5_Q bucket6_Q bucket7_Q bucket8_Q bucket9_Q ltd_iss_all_other, by(bucket)

gen logcount = log(count)

reg logcount bucket bucket_2-bucket_8 bucket4-bucket13 if ltd_iss_all_other  > 2000 & ltd_iss_all_other  < 40000 

scalar fp = exp((_b[bucket] * 10) + (_b[bucket_2] * 10^2) + (_b[bucket_3] * 10^3) + (_b[bucket_4] * 10^4) + (_b[bucket_5] * 10^5) + (_b[bucket_6] * 10^6) + (_b[bucket_7] * 10^7) + (_b[bucket_8] * 10^8)  + _b[_cons]) * exp((e(rmse)^2/2))
gen pcount = 0
replace pcount = exp((_b[bucket] * bucket) + (_b[bucket_2] * bucket_2) + (_b[bucket_3] * bucket_3) + (_b[bucket_4] * bucket_4) + (_b[bucket_5] * bucket_5) + (_b[bucket_6] * bucket_6) + (_b[bucket_7] * bucket_7) + (_b[bucket_8] * bucket_8) + _b[_cons]) * exp((e(rmse)^2/2)) 

include "Tables/Bootstrap Calcs.do"

* average debt foregone 
return scalar perc_beh_resp = (((actbcount - cfbcount) * 500) / fp)/(10000 + (((actbcount - cfbcount) * 500) / fp))

end


 ***********
 * Table 3 *
 ***********

 
foreach tc in 1 2 3 3.5 4 5 5.5 {

use "Data/Census w-restrictions.dta", clear

expand 2, gen(dupindicator)
replace type_code = 3.5 if (type_code == 1 | type_code == 2 | type_code == 3) & dupindicator == 1
replace type_code = 5.5 if (type_code == 4 | type_code == 5) & dupindicator == 1

keep if type_code == `tc'

drop if (year == 2010 & fyend <= 630) | (year == 2011 & fyend > 630)

gen bucket = .
 forvalues x = 1000(500)60000 {
 replace bucket = `x' if ltd_iss_all_other > `x' - 500 & ltd_iss_all_other <= `x' 
 }
 
replace bucket = bucket/1000
 
forvalues y = 2/14 {
gen bucket_`y' = bucket^`y'
}

gen Qdummy = ltd_iss_all_other <= 10000
gen bucket_Q = bucket * Qdummy

forvalues y = 2/14 {
gen bucket`y'_Q = bucket_`y' * Qdummy
}

gen bucket_alt = round((bucket/0.5) - 16)
forvalues q = 1(1)16 {
gen bucket`q' = bucket_alt == `q'
}

drop bucket_alt
keep ltd_iss_all_other id bucket* type_code Qdummy 

save "File 1 for Bootstrap.dta", replace

sort bucket
by bucket: egen count = count(bucket) 
count if ltd_iss_all_other >= 0 
scalar totalcount = r(N)
 
drop if ltd_iss_all_other > 60000 | ltd_iss_all_other < 1000

collapse (mean) count bucket1-bucket16 bucket_2-bucket_14 Qdummy bucket_Q bucket2_Q bucket3_Q bucket4_Q bucket5_Q bucket6_Q bucket7_Q bucket8_Q bucket9_Q ltd_iss_all_other, by(bucket)

gen logcount = log(count)

reg logcount bucket bucket_2-bucket_8 bucket4-bucket13 if ltd_iss_all_other  > 2000 & ltd_iss_all_other  < 40000 

scalar fp = exp((_b[bucket] * 10) + (_b[bucket_2] * 10^2) + (_b[bucket_3] * 10^3) + (_b[bucket_4] * 10^4) + (_b[bucket_5] * 10^5) + (_b[bucket_6] * 10^6) + (_b[bucket_7] * 10^7) + (_b[bucket_8] * 10^8)  + _b[_cons]) * exp((e(rmse)^2/2))
gen pcount = 0
replace pcount = exp((_b[bucket] * bucket) + (_b[bucket_2] * bucket_2) + (_b[bucket_3] * bucket_3) + (_b[bucket_4] * bucket_4) + (_b[bucket_5] * bucket_5) + (_b[bucket_6] * bucket_6) + (_b[bucket_7] * bucket_7) + (_b[bucket_8] * bucket_8) + _b[_cons]) * exp((e(rmse)^2/2)) 

include "Tables/Coefficient Calcs.do"

local perc_beh_resp = (((actbcount - cfbcount) * 500) / fp)/(10000 + (((actbcount - cfbcount) * 500) / fp))

simulate totmanip = ((cfacount - actacount) / totalcount) inranmanip = ((cfacount - actacount) / cfacount)  totmanip_ex = ((actbcount - cfbcount) / totalcount) inranmanip_ex = ((actbcount - cfbcount) / cfacount) perc_beh_resp = ((((actbcount - cfbcount) * 500) / fp)/(10000 + (((actbcount - cfbcount) * 500) / fp))), reps(500) seed(20316): debt_boot_3

* Standard Errors
reg inranmanip
sum inranmanip_ex
local inranmanip_ex_se = r(sd)

sum perc_beh_resp
local perc_beh_resp_se = r(sd)

outreg2 using "Table 3", append adds(Excess Mass, `inranmanip_ex', Excess Mass_SE, `inranmanip_ex_se', Delta d, `perc_beh_resp', Delta d_SE, `perc_beh_resp_se') nocons nor2 adec(2) nonotes noobs 
}

